#pragma once

#include "Resource.h"

#define WM_TRAY_NOTIFY	WM_USER + 100

class CUITrayIconWnd : public CWindowImpl<CUITrayIconWnd>
{
public:
	DECLARE_WND_CLASS_EX(L"GaojieDriveTray", 0, -1)

	CUITrayIconWnd();
	~CUITrayIconWnd();

	static DWORD GetWndStyle(DWORD dwStyle) { return WS_POPUP; }

	BEGIN_MSG_MAP(CUITrayIconWnd)
		MESSAGE_HANDLER(WM_CREATE, OnCreate)
		MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
		MESSAGE_HANDLER(WM_TRAY_NOTIFY, OnTrayNotify)
		MESSAGE_HANDLER(m_uTaskbarCreated, OnTaskbarCreated)
		COMMAND_ID_HANDLER(IDM_OPEN_FOLDER, OnOpenFolder)
		COMMAND_ID_HANDLER(IDM_SETTINGS, OnSettings)
		COMMAND_ID_HANDLER(IDM_ABOUT, OnAbout)
		COMMAND_ID_HANDLER(IDM_EXIT, OnExit)
	END_MSG_MAP()

private:
	LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnTaskbarCreated(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnOpenFolder(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	LRESULT OnSettings(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	LRESULT OnAbout(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	LRESULT OnExit(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

	void OnFinalMessage(HWND) override;
	void AddTrayIcon();
	void DelTrayIcon();
	void OnContextMenu(int x, int y);

	UINT  m_uTaskbarCreated;
	HMENU m_hMenu;
};
